package com.xinghanlaser.applet.points;

import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.xinghanlaser.applet.base.flow.core.BasePoint;
import com.xinghanlaser.applet.base.flow.enums.PointEnum;
import com.xinghanlaser.applet.entity.TopicHandleDetail;
import com.xinghanlaser.applet.service.ITopicHandleDetailService;
import com.xinghanlaser.applet.service.ITopicHandleHistoryService;
import com.xinghanlaser.applet.service.ITopicService;
import com.xinghanlaser.applet.vo.point.AfterSalesSupervisorViewVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * <p>
 *
 * <p>
 *
 * @author: mftuo 陀铭峰
 * @since: 2024/5/13 9:06
 */
@Component
public class AfterSalesSupervisorViewPoint extends BasePoint<AfterSalesSupervisorViewVO> {
    @Resource
    private ITopicService topicService;

    @Resource
    private ITopicHandleDetailService handleService;

    @Resource
    private ITopicHandleHistoryService historyService;

    @Override
    @DSTransactional
    protected void pointOperation(AfterSalesSupervisorViewVO vo) {
        // 校验申请单是否存在
        final Long topicId = vo.getTopicId();

        topicService.validatedTopicId(topicId);

        // 更新处理流程信息
        TopicHandleDetail handleEntity = topicService.getHandleEntityByTopicId(topicId);
        if(handleEntity.getCurrentPointId().equals(PointEnum.ADD_TOPIC.getPointId())){
            handleEntity.setCurrentPointId(getPointId());
            handleService.updateById(handleEntity);

            // 保存历史流程信息
            historyService.saveHistory(
                    handleEntity.getId(),
                    getPointId(),
                    "已查看",
                    null
            );
        }

    }

    @Override
    protected Class<AfterSalesSupervisorViewVO> getPointDataType() {
        return AfterSalesSupervisorViewVO.class;
    }

    @Override
    public Long getPointId() {
        return 2L;
    }
}
